//
//  RHLocalCellVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/4/8.
//

#import "RHLocalPackDetailVC.h"
#import "JXCategoryView.h"
#import "JXCategoryListContainerView.h"
#import "RHLocalPackDataVC.h"
#import "RHLocalCellVC.h"
#import "RHNavTitleView.h"

@interface RHLocalPackDetailVC ()
<JXCategoryListContainerViewDelegate,JXCategoryViewDelegate,JXCategoryTitleViewDataSource>

@property (nonatomic, strong) NSArray *titles;

@property (nonatomic, strong) JXCategoryTitleView *categoryView;

@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;

@property (nonatomic, strong) RHNavTitleView *titleView;
@end

@implementation RHLocalPackDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:CFTabViewBgColor];
    self.titles = @[@"数据".rh_localized,@"电芯".rh_localized];
    
    [self setupUI];
}

- (void)setupUI
{
    self.titleView = [[RHNavTitleView alloc]init];
    [self.titleView hideArrowImg];
    self.titleView.devNameLab.text = [NSString stringWithFormat:@"PACK %ld",self.packIndex+1];
    self.titleView.devIdLab.text = self.packSN;
    self.titleView.devIdLab.textColor = kRGB(86, 194, 113);
    self.navigationItem.titleView = self.titleView;
    
    _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    [self.view addSubview:self.listContainerView];
    
    _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, 50)];
    self.categoryView.titles = self.titles;
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.delegate = self;
//    self.categoryView.cellWidth = (SCREEN_WIDTH-30)/2;
    self.categoryView.titleSelectedColor = kCOLOR_HEX(@"323233");
    self.categoryView.titleColor = kCOLOR_HEX(@"969799");
    self.categoryView.titleFont = [UIFont systemFontOfSize:14];
    self.categoryView.titleSelectedFont = [UIFont boldSystemFontOfSize:14];
    self.categoryView.titleColorGradientEnabled = YES;
    self.categoryView.titleLabelZoomEnabled = NO;
    self.categoryView.titleLabelZoomScale = 1.0;
    self.categoryView.cellSpacing = 20;
    self.categoryView.contentEdgeInsetLeft = 55;
    self.categoryView.contentEdgeInsetRight = 55;
    self.categoryView.titleLabelVerticalOffset = 0;
    [self.view addSubview:self.categoryView];
    self.categoryView.listContainer = self.listContainerView;
    
    //下划线
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorColor = CFMainColor;
    lineView.indicatorWidth = JXCategoryViewAutomaticDimension;
   
    self.categoryView.indicators = @[lineView];
    
//    JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
//     backgroundView.size = CGSizeMake(60, 3);
//     backgroundView.indicatorColor = CFMainColor;
//     backgroundView.indicatorHeight = 3;
//     backgroundView.indicatorWidth = 60;
//     backgroundView.verticalMargin = -10;
//     backgroundView.indicatorCornerRadius = 1.5;
//
//     _categoryView.indicators = @[backgroundView];
    
    
    [_categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.mas_offset(0);
        make.height.mas_equalTo(50);
    }];
    
    [_listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.equalTo(self.categoryView.mas_bottom).offset(0);
        make.bottom.mas_offset(0);
    }];
    
   
}



#pragma mark - JXCategoryViewDelegate

// 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件，不关心具体是点击还是滚动选中的。
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    NSLog(@"%@", NSStringFromSelector(_cmd));
    // 侧滑手势处理
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
    
   
}

// 滚动选中的情况才会调用该方法
- (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

#pragma mark - JXCategoryListContainerViewDelegate
// 返回列表的数量
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return  self.titles.count;
}

// 返回各个列表菜单下的实例，该实例需要遵守并实现 <JXCategoryListContentViewDelegate> 协议
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {


    if(index == 0){
        RHLocalPackDataVC *packDadaVC = [[RHLocalPackDataVC alloc]init];
        packDadaVC.packIndex = self.packIndex;
        return packDadaVC;
    }else if(index == 1){
        RHLocalCellVC *cellVC = [[RHLocalCellVC alloc]init];
        cellVC.packIndex = self.packIndex;
        return cellVC;
    }
    
    
    
    return nil;
}
@end
